<template>
  <div id="app">
    <!-- 这里是会被缓存的视图组件，比如page,page1,page2 -->
    <!-- <keep-alive>
      <router-view v-if="$route.meta.keepAlive">
        这里是会被缓存的视图组件，比如page,page1,page2 
      </router-view>
    </keep-alive> -->

    <router-view />
  </div>
</template>

<script>
import { watch } from 'vue'
export default {
  data() {
    return {
      windowWidth: window.innerWidth,
      baseFontSize: 16
    }
  },

  methods: {
    handleResize() {
      this.windowWidth = window.innerWidth
      this.setRem()
    },

    // 响应式
    setRem() {
      const html = document.documentElement
      const windowWidth = window.innerWidth
      html.style.fontSize = (windowWidth / 1920) * this.baseFontSize + 'px'
      console.log('fontSize: ', (windowWidth / 1920) * this.baseFontSize + 'px')
    }
  },

  async created() {
    this.handleResize()
  },

  mounted() {
    window.addEventListener('resize', this.handleResize)
  },

  beforeUnmount() {
    window.removeEventListener('resize', this.handleResize)
  }
}
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

* {
  padding: 0;
  margin: 0;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}

div {
  box-sizing: border-box;
  position: relative;
  text-align: left;
}

// ::-webkit-scrollbar 用于设置整个滚动条的宽度。
// ::-webkit-scrollbar-thumb 用于设置滚动条的滑块（拖动条）的样式。
// ::-webkit-scrollbar-track 用于设置滚动条的轨道的样式。
div::-webkit-scrollbar {
  width: 0.3125rem;
}
div::-webkit-scrollbar-thumb {
  background-color: #888;
  border-radius: 6px;
}
div::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}
</style>
